﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExtensionsExcercise
{
    public static class IEnumerableExtensions
    {
        public static int Sum(this IEnumerable<int> enumeration)
        {
            //Console.WriteLine("Sum<int>");

            int sum = 0;

            foreach (var item in enumeration)
            {
                sum += item;
            }

            return sum;
        }

        public static double Sum(this IEnumerable<double> enumeration)
        {
            //Console.WriteLine("Sum<double>");

            double sum = 0;

            foreach (var item in enumeration)
            {
                sum += item;
            }

            return sum;
        }    

        public static decimal Sum<T>(this IEnumerable<T> enumeration)
        {
            //Console.WriteLine("Sum<T>");

            decimal sum = 0;

            foreach (var item in enumeration)
            {
                decimal value;

                try
                {
                    value = Convert.ToDecimal(item);
                }
                catch (SystemException)
                {
                    value = 0;                                            
                }

                sum += value;
            }

            return sum;
        }

        public static int Sum(this IEnumerable<Student> enumeration)
        {
            //Console.WriteLine("Sum<Student>");
            return 0;
        }
    }
}
